use "D:\Dropbox\Abrams Doctrine\yougov\bck_JoGSS_2022_replication_data.dta", clear

* Table 1 -- Effect of Treatments on Personally Affected Perception and Casualty Assessments *
ologit personalcosts draft reserves both gop5 dem5 male age education white nomilserve
outreg2 using table1, word dec(2) label replace
ologit cascosts draft reserves both gop5 dem5 male age education white nomilserve
outreg2 using table1, word dec(2) label append

* Table 2 -- Manpower Policies, Cost Estimates, and War Support *
logit supportforce draft reserves both   gop5 dem5 male age education white nomilserve
test draft=reserves
test both=reserves
outreg2 using table2, word dec(2) label replace
logit supportforce draft reserves both personalcosts cascosts gop5 dem5 male age education white nomilserve
outreg2 using table2, word dec(2) label append

* Table 3 -- Mediation Analysis *
* Install KHB package if necessary: http://fmwww.bc.edu/repec/bocode/k/khb.html *
khb logit supportforce draft both reserves || personalcosts cascosts, concomitant(gop5 dem5 male age education white nomilserve) disentangle

* Table 4 -- Effect of Cost Perceptions by Military Service *
logit supportforce draft reserves both personalcosts cascosts gop5 dem5 male age education white nomilserve personalcostsxnomilserve
outreg2 using table4, word dec(2) label replace
logit supportforce draft reserves both personalcosts cascosts gop5 dem5 male age education white nomilserve personalcostsxnomilserve cascostsxnomilserve
outreg2 using table4, word dec(2) label append

* Figure 2 -- Difference in Means across Treatments and Control *
gen means = .
gen ns = .
gen sds = .
gen ses = .
gen label = _n
replace label = . if label > 4

sum supportforce if avf == 1
replace means = r(mean) if label == 1
replace sds = r(sd) if label == 1
replace ns = r(N) if label == 1
replace ses = sds/sqrt(ns) if label == 1

sum supportforce if draft == 1
replace means = r(mean) if label == 2
replace sds = r(sd) if label == 2
replace ns = r(N) if label == 2
replace ses = sds/sqrt(ns) if label == 2

sum supportforce if reserves == 1
replace means = r(mean) if label == 3
replace sds = r(sd) if label == 3
replace ns = r(N) if label == 3
replace ses = sds/sqrt(ns) if label == 3

sum supportforce if both == 1
replace means = r(mean) if label == 4
replace sds = r(sd) if label == 4
replace ns = r(N) if label == 4
replace ses = sds/sqrt(ns) if label == 4

gen meansdiff = means-.69918698
serrbar meansdiff se label if label>1, scale(1.96) ylabel(-.2 "-20%" -.15 "-15%" -.1 "-10%" -.05 "-5%" 0 "0%" .05 "5%") xscale(range(1.75 4.25)) xlabel(2 "Draft" 3 "Reserves/Guard" 4 "Both") ytitle("Change in Support for Force" " ") xtitle("") graphregion(color(white)) yline(0)

ttest supportforce if draft == 1|reserves==1, by(reserves)
ttest supportforce if both == 1|reserves==1, by(reserves)

* Figure 3 -- Effects of Costs Estimates by Military Service -- using simulations *
* Install clarify if necessary: https://gking.harvard.edu/clarify *
gen fig1mean = .
gen fig1upper = .
gen fig1lower = .
gen fig1label = _n
replace fig1label = . if fig1label > 4
label define fig1labels 1 "Personal Costs X Military" 2 "Personal Costs X Non-Military" 3 "Casualty Estimate X Military" 4 "Casualty Estimate X Non-Military"
label values fig1label fig1labels
label var fig1label ""

estsimp logit supportforce draft reserves both personalcosts cascosts gop5 dem5 male age education white nomilserve personalcostsxnomilserve cascostsxnomilserve
setx median
setx gop5 0 dem5 0 personalcostsxnomilserve 0 cascostsxnomilserve 0 nomilserve 0

setx personalcosts 2 personalcostsxnomilserve 0 cascostsxnomilserve 0
simqi, genpr(preds0 preds1)
egen baseline1 = mean(preds1)
drop preds0 preds1

setx personalcosts 4
simqi, genpr(preds0 preds1)
_pctile preds1, p(2.5,97.5)
replace fig1upper = r(r1)-`=baseline1[1]' if fig1label == 1
replace fig1lower = r(r2)-`=baseline1[1]' if fig1label == 1 
egen x = mean(preds1)
replace fig1mean = x-`=baseline1[1]' if fig1label == 1
drop x preds0 preds1

setx personalcosts 2 nomilserve 1 personalcostsxnomilserve 2 cascostsxnomilserve median
simqi, genpr(preds0 preds1)
egen baseline2 = mean(preds1)
drop preds0 preds1

setx personalcosts 4 personalcostsxnomilserve 4
simqi, genpr(preds0 preds1)
_pctile preds1, p(2.5,97.5)
replace fig1upper = r(r1)-`=baseline2[1]' if fig1label == 2
replace fig1lower = r(r2)-`=baseline2[1]' if fig1label == 2 
egen x = mean(preds1)
replace fig1mean = x-`=baseline2[1]' if fig1label == 2
drop x preds0 preds1

setx personalcosts 2 nomilserve 0 personalcostsxnomilserve 0 cascostsxnomilserve 0
setx cascosts 6
simqi, genpr(preds0 preds1)
_pctile preds1, p(2.5,97.5)
replace fig1upper = r(r1)-`=baseline1[1]' if fig1label == 3
replace fig1lower = r(r2)-`=baseline1[1]' if fig1label == 3 
egen x = mean(preds1)
replace fig1mean = x-`=baseline1[1]' if fig1label == 3
drop x preds0 preds1

setx cascosts 6 cascostsxnomilserve 6 personalcostsxnomilserve 2
simqi, genpr(preds0 preds1)
_pctile preds1, p(2.5,97.5)
replace fig1upper = r(r1)-`=baseline2[1]' if fig1label == 4
replace fig1lower = r(r2)-`=baseline2[1]' if fig1label == 4 
egen x = mean(preds1)
replace fig1mean = x-`=baseline2[1]' if fig1label == 4
drop x preds0 preds1

*eclplot fig1mean fig1lower fig1upper fig1label, ylabel(.3 .2 .1 0 -.1 -.2 -.3 -.4 -.5) ytitle("Change in probability" " ") xtitle("") xscale(range(.5 4.5)) xlabel(1 2 3 4,angle(vertical)) yline(0) graphregion(fcolor(white))  ciopts(blcolor(black)) estopts(mcolor(black) msymbol(circle))
eclplot fig1mean fig1lower fig1upper fig1label, xlabel(.3 .2 .1 0 -.1 -.2 -.3 -.4 -.5) xtitle(" " "Change in Probability of Support") ytitle("") yscale(range(.5 4.5)) ylabel(1 2 3 4,angle(horizontal)) xline(0) graphregion(fcolor(white))  ciopts(blcolor(black)) estopts(mcolor(black) msymbol(circle)) horizontal

* SUPPORTING INFORMATION *

* SI Figure 1 -- Interactioon in Linear Model *
reg supportforce draft reserves both c.personalcosts##c.nomilserve cascosts gop5 dem5 male age education white 
margins, at(personalcosts=(0(1)4) nomilserve=(0(1)1)) vsquish
marginsplot, ti("Linear Probability Model") graphregion(color(white)) recast(line) recastci(rarea) ///
plot1opts(lpattern("--") lcolor(black) color(gs5)) ci1opts(color(gs3%90)) ///
plot2opts(lcolor(black) color(gs10)) ci2opts(color(gs10%80)) ///
legend(order(3 "Some connection to military" 4 "No connection to military"))

* SI Table 1: Balance across experimental groups *
oneway dem5 BOS103_rand, tab
oneway gop5 BOS103_rand, tab
oneway male BOS103_rand, tab
oneway age BOS103_rand, tab
oneway education BOS103_rand, tab
oneway white BOS103_rand, tab
oneway nomilserve BOS103_rand, tab

* SI Table 2: Treatment Effects with Controls *
logit supportforce draft reserves both gop5 dem5 male age education white 
outreg2 using sitable2, word dec(2) label replace
logit supportforce draft reserves both gop5 dem5 male age education white nomilserve 
outreg2 using sitable2, word dec(2) label append

* SI Table 3: Indirect Effects of Treatments by Cost Perceptions *
khb logit supportforce draft both reserves || personalcosts cascosts, concomitant(gop5 dem5 male age education white nomilserve) disentangle

* SI Table 4: Personal Costs Relationship Not Moderated by Treatment *
logit supportforce draft reserves both personalcosts cascosts gop5 dem5 male age education white
outreg2 using sitable4, word dec(2) label replace
logit supportforce draft reserves both personalcosts cascosts gop5 dem5 male age education white  personalcostsxdraft personalcostsxreserves personalcostsxboth
outreg2 using sitable4, word dec(2) label append

* SI Table 5: Excluding Personal Contact *
ologit personalcosts draft reserves both gop5 dem5 male age education white 
outreg2 using sitable5, word dec(2) label replace
ologit cascosts draft reserves both gop5 dem5 male age education white 
outreg2 using sitable5, word dec(2) label append
logit supportforce draft reserves both personalcosts cascosts gop5 dem5 male age education white 
outreg2 using sitable5, word dec(2) label append sortvar(draft reserves both personalcosts cascosts gop5 dem5 male age education white )

* SI Table 6: Linear Probability Models *
reg supportforce draft reserves both personalcosts cascosts gop5 dem5 male age education white nomilserve personalcostsxnomilserve
outreg2 using sitable6, word dec(2) label replace
reg supportforce draft reserves both personalcosts cascosts gop5 dem5 male age education white nomilserve personalcostsxnomilserve cascostsxnomilserve
outreg2 using sitable6, word dec(2) label append

* SI Table 7: Treatment Effects Are Not Moderated by Military Service *
logit supportforce draft reserves both gop5 dem5 male age education white 
outreg2 using sitable7, word dec(2) label replace
logit supportforce draft reserves both gop5 dem5 male age education white nomilserve draftxnomilserve reservesxnomilserve bothxnomilserve
outreg2 using sitable7, word dec(2) label append
logit supportforce draft reserves both gop5 dem5 male age education white milserve draftxmilserve reservesxmilserve bothxmilserve
outreg2 using sitable7, word dec(2) label append

* SI Table 8: Draft Treatment Moderation *
* Draft risk measures *
gen male18to26 = 0
replace male18to26 = 1 if male == 1 & age < 27
gen maleunder41 = 0
replace maleunder41 = 1 if male == 1 & age < 41
gen anyunder41 = 0
replace anyunder41 = 1 if age < 41

gen draftxmale18to26 = draft *male18to26
gen draftxmaleunder41 = draft * maleunder41
gen draftxanyunder41 = draft * anyunder41

label var male18to26 "Men 18-26"
label var maleunder41 "Men 18-40"
label var anyunder41 "Men and women 18-40"

label var draftxmale18to26 "Draft treatment X Men 18-26"
label var draftxmaleunder41 "Draft treatment X Men 18-40"
label var draftxanyunder41 "Draft treatment X Men and women 18-40"

logit supportforce draft draftxmale18to26 male18to26 reserves both gop5 dem5 education white nomilserve
outreg2 using sitable8, word dec(2) label replace
logit supportforce draft draftxmaleunder41 maleunder41 reserves both gop5 dem5 education white nomilserve
outreg2 using sitable8, word dec(2) label append
logit supportforce draft draftxanyunder41 anyunder41 reserves both gop5 dem5 education white nomilserve
outreg2 using sitable8, word dec(2) label append sortvar(draft draftxmale18to26  draftxmaleunder41 draftxanyunder41 reserves both gop5 dem5 male age education white nomilserve male18to26 maleunder41 anyunder41)
